package main

import (
    "github.com/gin-contrib/cors"
    "github.com/gin-gonic/gin"
    "github.com/micro/go-micro/v2/web"
    "gonaio_base/constant"
    "gonaio_base/middleware"
    "gonaio_gateway/config"
    "gonaio_gateway/router"
    "time"
)

func main() {
    r := gin.Default()
    //gin.SetMode(gin.ReleaseMode)
    gin.SetMode(gin.DebugMode)
    //r.Use(gin.Logger())
    r.Use(gin.Recovery())
    r.Use(middleware.NewJWT(bconstant.DEFAULT_TOKEN_KEY, bconstant.DEFAULT_TOKEN_EXPIRE_TIME, config.M))
    r.Use(middleware.NewHystrix())
    r.Use(cors.New(cors.Config{
        AllowAllOrigins:  true,
        AllowMethods:     []string{"GET", "POST", "PUT", "HEAD", "PATCH", "DELETE", "OPTIONS"},
        AllowHeaders:     []string{"Content-Type, Content-Encoding, Authorization, CaptchaCode, CaptchaKey, OTP, Authorization2, Accept-Language, Accept-Encoding"},
        ExposeHeaders:    []string{"Content-Length"},
        AllowCredentials: false,
        MaxAge:           12 * time.Hour,
    }))
    service := web.NewService(web.Address(bconstant.DEFAULT_HOST_PORT))
    service.Init()
    service.Handle("/", router.MainRouter(r))
    service.Run()
}
